package liurong.driver.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadLocalTest {
	public static ThreadLocal<String> threadLocal = new ThreadLocal<String>();

	public static void main(String[] args) throws Exception {
		threadLocal.set("main");
		ExecutorService executorService = Executors.newFixedThreadPool(2);
		for (int i = 0; i < 10; i++) {
			MyThread myThread = new MyThread(i);
			executorService.execute(myThread);
		}
		System.out.println(threadLocal.get());
	}

}

class MyThread extends Thread {
	private int i;

	public MyThread() {

	}

	public MyThread(int i) {
		this.i = i;

	}

	public void run() {
		if (i == 1) {
			ThreadLocalTest.threadLocal.set("我是线程 ：" + i);
		}
		System.out.println(i + ":" + ThreadLocalTest.threadLocal.get());
	}
}
